home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / common / util / setSocketOptions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  3.2 KB  |  110 lines

  1. /*
  2.  *   $RCSfile: setSocketOptions.c,v $  
  3.  *   $Revision: 1.2 $  
  4.  *   $Date: 1996/05/04 23:51:45 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "sysdefs.h"
  38. #include <fcntl.h>
  39. #include <netinet/tcp.h>
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "util_funcs.h"
  45.  
  46.  int
  47. setSocketOptions (
  48.     int fd,                /* socket id */
  49.     int sendBufSize,
  50.     int receiveBufSize
  51. )
  52.  
  53. {
  54.     struct protoent        *protoInfo;
  55.     int                    one = 1;    /* for 4.3 BSD style setsockopt() */
  56.     struct linger         lingerInfo;
  57.  
  58.     TRACE(TR_MSG, TR_LEVEL_1);
  59.  
  60.     /*
  61.       *    set socket to not delay sending data
  62.      */
  63.     protoInfo = getprotobyname("tcp");
  64.     if (protoInfo == NULL) {
  65.         SM_ERROR(TYPE_SYS, errno);
  66.         return(esmFAILURE);
  67.     }
  68.     if (setsockopt(fd, protoInfo->p_proto, TCP_NODELAY, (char*) &one, sizeof(one)) != 0) {
  69.         SM_ERROR(TYPE_SYS, errno);
  70.         return(esmFAILURE);
  71.     }
  72.  
  73.     if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *) &sendBufSize, sizeof(sendBufSize)) != 0) {
  74.         SM_ERROR(TYPE_SYS, errno);
  75.         return(esmFAILURE);
  76.     }
  77.     if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *) &receiveBufSize, sizeof(receiveBufSize)) != 0) {
  78.         SM_ERROR(TYPE_SYS, errno);
  79.         return(esmFAILURE);
  80.     }
  81.  
  82. #ifdef COMMENT
  83.     {
  84.         int                    length;
  85.         if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &lingerInfo, &length) != 0) {
  86.             SM_ERROR(TYPE_SYS, errno);
  87.             return(esmFAILURE);
  88.         }
  89.         if (length != sizeof(lingerInfo)) {
  90.             printf("getsockopt return linger size of %d instead of %d\n",
  91.                    length, sizeof(lingerInfo));
  92.         }
  93.         printf("Socket had linger_onoff:%d, l_linger:%d\n", lingerInfo.l_onoff, lingerInfo.l_linger);
  94.     }
  95. #endif COMMENT;
  96.  
  97.     /*
  98.      *    Make sure the sockets don't wait to send any leftover date
  99.      *  once they have been closed
  100.      */
  101.     lingerInfo.l_onoff = 0;
  102.     lingerInfo.l_linger = 0;
  103.     if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &lingerInfo, sizeof(lingerInfo)) != 0) {
  104.         SM_ERROR(TYPE_SYS, errno);
  105.         return(esmFAILURE);
  106.     }    
  107.  
  108.     return(esmNOERROR);
  109. }
  110.